{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "d58c292b-b6f9-4b7c-a96b-8100721a15d8",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "27aa8587-062b-4555-ae3b-28e14f9a0267",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0, 10, 20, 30, 40, 50, 60, 70, 80, 90])"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array = np.arange(0,100,10)\n",
    "liao_array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "3422f022-0067-4d99-9bd7-7ce4fc772a4e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.69905124, 0.92664246, 0.23342895, 0.84548767, 0.79186873,\n",
       "       0.61613692, 0.96604215, 0.96454138, 0.04665587, 0.88020453])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "random_array = np.random.rand(10)\n",
    "random_array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "24e72a08-ec4a-40b9-ac3f-c2c51858d0f2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ True,  True, False,  True,  True,  True,  True,  True, False,\n",
       "        True])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mask = random_array > 0.5\n",
    "mask"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "9c237f73-bf0a-4e33-89f7-22d042ba7e3f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0, 10, 30, 40, 50, 60, 70, 90])"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array[mask]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "95c3898b-a448-497b-b9a4-05fe9f8514b8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([False, False, False,  True,  True])"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array = np.array([10,20,30,40,50])\n",
    "liao_array > 30"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "b36c1715-98dd-45ce-9aac-03b34cc7947c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(array([3, 4], dtype=int64),)"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.where(liao_array > 30)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "ab349be0-dafc-4211-8bf5-621717cb6b8d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([40, 50])"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array[np.where(liao_array > 30)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "ed76fb73-3f21-4ed1-9c90-19feb6e7c2d7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1., 2., 3., 4., 5.], dtype=float32)"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array = np.array([1,2,3,4,5], dtype=np.float32)\n",
    "liao_array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "236cdfaa-a7d5-49a3-abd2-9312c9867163",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dtype('float32')"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array.dtype"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "08435a86-4ac7-4a4b-9b3d-8bc08e94aa8d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "20"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array.nbytes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "daf0c92b-364f-4518-8e1c-ff560b50baac",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 10, 3.5, 'str'], dtype=object)"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array = np.array([1,10,3.5,'str'], dtype = object) ### 新版Numpy 不用 np.object\n",
    "liao_array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "cb4b737e-58b1-453c-ae89-1ed812aab675",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([2, 20, 7.0, 'strstr'], dtype=object)"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array * 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "d140cb31-7864-436f-950b-c54ea26acf50",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1., 2., 3., 4., 5.], dtype=float32)"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array = np.array([1,2,3,4,5])\n",
    "np.asarray(liao_array,dtype = np.float32)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "f0047e39-9a84-4664-8498-81bfe1088f89",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 2, 3, 4, 5])"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "203bfff3-8acb-41de-8aba-0724943d9567",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1., 2., 3., 4., 5.], dtype=float32)"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array2 = np.asarray(liao_array, dtype = np.float32)\n",
    "liao_array2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "ce855929-66dd-40ff-9837-71d04d1a458d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 2, 3, 4, 5])"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3467e247-9ae5-45a8-9341-56e90c46b116",
   "metadata": {},
   "source": [
    "### 这说明 np.asarray 创建的新的数组不会影响原数组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "e9c12855-25c3-4b78-9b4d-8bc7e8c4ccba",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1., 2., 3., 4., 5.], dtype=float32)"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array.astype(np.float32)  ### 也可以使用 .astype() "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "c34e985f-7d77-48fc-b2ab-2635d4fbdd88",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 2, 3, 4, 5])"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5668763b-0807-4e25-9d04-2e588fa51dbd",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
